/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fotoxop;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.ImageFilter;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.statistics.HistogramType;

/**
 *
 * @author Paulo Ricardo
 */
public class Principal extends javax.swing.JFrame {

    /**
     * Creates new form Principal
     */
    private BufferedImage ImagemAtual;

    public Principal() {
        initComponents();
        //setExtendedState( MAXIMIZED_BOTH );
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jbtnAbrirImagem = new javax.swing.JButton();
        EdtCaminhoImagem = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        ImagemEmEdicao = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        LbPontodeProva = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jmenuPrincipal = new javax.swing.JMenuBar();
        jmenuEfeitos = new javax.swing.JMenu();
        jmiNegativo = new javax.swing.JMenuItem();
        jmiRotacao90AntiHorario = new javax.swing.JMenuItem();
        jmiRotacao90Horario = new javax.swing.JMenuItem();
        jmirotacao180 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jmiLogaritmo = new javax.swing.JMenuItem();
        jmiQuantizacao = new javax.swing.JMenuItem();
        jmiAntiLogaritmo = new javax.swing.JMenuItem();
        jmiPotencia = new javax.swing.JMenuItem();
        jmiRaiz = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jmiMedia = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jmiHistograma = new javax.swing.JMenuItem();
        jMenuItem15 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();
        jmenuSobre = new javax.swing.JMenu();
        jmenuAjuda = new javax.swing.JMenu();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("FotoXop");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Selecionar a Imagem"));

        jbtnAbrirImagem.setText("Selecione a Imagem");
        jbtnAbrirImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAbrirImagemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtnAbrirImagem, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
                    .addComponent(EdtCaminhoImagem))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(EdtCaminhoImagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnAbrirImagem)
                .addGap(20, 20, 20))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Imagem"));

        ImagemEmEdicao.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        ImagemEmEdicao.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                ImagemEmEdicaoMouseMoved(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(ImagemEmEdicao, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(72, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(ImagemEmEdicao, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Ponto de prova"));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LbPontodeProva)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LbPontodeProva)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Histograma"));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jmenuEfeitos.setText("Efeitos");

        jmiNegativo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jmiNegativo.setText("Negativo");
        jmiNegativo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiNegativoActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiNegativo);

        jmiRotacao90AntiHorario.setText("Rotação 90° [Anti-Horario]");
        jmiRotacao90AntiHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiRotacao90AntiHorarioActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiRotacao90AntiHorario);

        jmiRotacao90Horario.setText("Rotação 90° [Horario]");
        jmiRotacao90Horario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiRotacao90HorarioActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiRotacao90Horario);

        jmirotacao180.setText("Rotação 180°");
        jmirotacao180.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmirotacao180ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmirotacao180);

        jMenuItem1.setText("Espelhamento Horizontal");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem1);

        jMenuItem2.setText("Espelhamento Vertical");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem2);

        jMenuItem3.setText("Amostragem");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem3);

        jmiLogaritmo.setText("Logaritmo");
        jmiLogaritmo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiLogaritmoActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiLogaritmo);

        jmiQuantizacao.setText("Quantização");
        jmiQuantizacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiQuantizacaoActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiQuantizacao);

        jmiAntiLogaritmo.setText("AntiLog");
        jmiAntiLogaritmo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiAntiLogaritmoActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiAntiLogaritmo);

        jmiPotencia.setText("Potencia");
        jmiPotencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiPotenciaActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiPotencia);

        jmiRaiz.setText("Raiz");
        jmiRaiz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiRaizActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiRaiz);

        jMenuItem10.setText("Min");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem10);

        jMenuItem9.setText("Max");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem9);

        jmiMedia.setText("Media");
        jmiMedia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiMediaActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiMedia);

        jMenuItem4.setText("Mediana");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem4);

        jMenuItem8.setText("Moda");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem8);

        jmiHistograma.setText("Histograma");
        jmiHistograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiHistogramaActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jmiHistograma);

        jMenuItem15.setText("Histograma Equalizado");
        jMenuItem15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem15ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem15);

        jMenuItem5.setText("Somar imagens");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem5);

        jMenuItem6.setText("Expansão");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem6);

        jMenuItem7.setText("Compressão");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem7);

        jMenuItem11.setText("Prewitt");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem11);

        jMenuItem12.setText("Sobel");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem12);

        jMenuItem13.setText("Desfoque Gaussiano");
        jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem13ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem13);

        jMenuItem14.setText("Scale2x");
        jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem14ActionPerformed(evt);
            }
        });
        jmenuEfeitos.add(jMenuItem14);

        jmenuPrincipal.add(jmenuEfeitos);

        jmenuSobre.setText("Sobre");
        jmenuSobre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jmenuSobreMouseClicked(evt);
            }
        });
        jmenuSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmenuSobreActionPerformed(evt);
            }
        });
        jmenuPrincipal.add(jmenuSobre);

        jmenuAjuda.setText("Ajuda");
        jmenuAjuda.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jmenuAjudaMouseClicked(evt);
            }
        });
        jmenuPrincipal.add(jmenuAjuda);

        setJMenuBar(jmenuPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 9, Short.MAX_VALUE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnAbrirImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAbrirImagemActionPerformed
        JFileChooser abrir = new JFileChooser();

       // FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPEG file", "jpg", "jpeg");
        //abrir.setFileFilter(filtro);
        //abrir.setFileFilter();
        int retorno = abrir.showOpenDialog(null);
        if (retorno == JFileChooser.APPROVE_OPTION) {
            final String caminho = abrir.getSelectedFile().getAbsolutePath();
            EdtCaminhoImagem.setText(caminho);

            try {
                ImagemAtual = ImageIO.read(new File(caminho));
            } catch (IOException ex) {
                Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
            }

            ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
            ImagemEmEdicao.setSize(ImagemAtual.getWidth(), ImagemAtual.getHeight());
        }
    }//GEN-LAST:event_jbtnAbrirImagemActionPerformed

    private void ImagemEmEdicaoMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ImagemEmEdicaoMouseMoved
        if (ImagemAtual != null) {
            Color cor = new Color(ImagemAtual.getRGB(evt.getX(), evt.getY()));
            int Vermelho = cor.getRed();
            int Verde = cor.getGreen();
            int Azul = cor.getBlue();
            LbPontodeProva.setText("X:" + evt.getX() + " Y:" + evt.getY() + " Vermelho:" + Vermelho + " Verde:" + Verde + " Azul:" + Azul);
        }
    }//GEN-LAST:event_ImagemEmEdicaoMouseMoved

    private void jmiNegativoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiNegativoActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Negativo(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiNegativoActionPerformed

    private void jmirotacao180ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmirotacao180ActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Rotacao180(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmirotacao180ActionPerformed

    private void jmiRotacao90AntiHorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiRotacao90AntiHorarioActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.RotacaoAntiHorario90(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiRotacao90AntiHorarioActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.EspelhamentoHorizontal(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.EspelhamentoVertical(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));

    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jmiRotacao90HorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiRotacao90HorarioActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.RotacaoHorario90(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiRotacao90HorarioActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        int amostra = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da amostragem:"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Amostragem(ImagemAtual, amostra);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jmiLogaritmoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiLogaritmoActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Logaritmo(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiLogaritmoActionPerformed

    private void jmiQuantizacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiQuantizacaoActionPerformed
        int level = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da quantização:"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Quantizacao(ImagemAtual, level);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiQuantizacaoActionPerformed

    private void jmiAntiLogaritmoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiAntiLogaritmoActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.AntiLogaritmo(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiAntiLogaritmoActionPerformed

    private void jmiPotenciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPotenciaActionPerformed
        double gama = Double.parseDouble(JOptionPane.showInputDialog(this, "Entre com o valor gama:"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Potencia(ImagemAtual, gama);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiPotenciaActionPerformed

    private void jmiRaizActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiRaizActionPerformed
        double gama = Double.parseDouble(JOptionPane.showInputDialog(this, "Entre com o valor gama:"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Raiz(ImagemAtual, gama);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiRaizActionPerformed

    private void jmenuSobreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmenuSobreMouseClicked
        try {
            Sobre ObjViewSobre = new Sobre();
            ObjViewSobre.setVisible(true);
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jmenuSobreMouseClicked

    private void jmenuAjudaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmenuAjudaMouseClicked
        Ajuda ObjViewAjuda = new Ajuda();
        ObjViewAjuda.setVisible(true);
    }//GEN-LAST:event_jmenuAjudaMouseClicked

    private void jmenuSobreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmenuSobreActionPerformed
        Ajuda ObjViewAjuda = new Ajuda();
        ObjViewAjuda.setVisible(true);
    }//GEN-LAST:event_jmenuSobreActionPerformed

    private void jmiMediaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiMediaActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Media(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jmiMediaActionPerformed

    private void jmiHistogramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiHistogramaActionPerformed

        
        
       double vetorvermelho[] = ProcessamentoFotoXop.getNCsImagem(ImagemAtual,"R");
       double vetorverde[] = ProcessamentoFotoXop.getNCsImagem(ImagemAtual,"G");
       double vetorazul[] = ProcessamentoFotoXop.getNCsImagem(ImagemAtual,"B");
            
            int quantidade = 256;
            
            HistogramDataset dataset = new HistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries("Vermelho", vetorvermelho, quantidade);
            dataset.addSeries("Verde", vetorverde, quantidade);
            dataset.addSeries("Azul", vetorazul, quantidade);
            String plotTitle = "Histograma";
            String xaxis = "Nivel de Cinza";
            String yaxis = "Frequencia";
            PlotOrientation orientation = PlotOrientation.VERTICAL;
            boolean show = false;
            boolean toolTips = false;
            boolean urls = false;

            // cria o gráfico
            JFreeChart grafico = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls);
             
            ChartPanel myChartPanel = new ChartPanel(grafico, true);

            myChartPanel.setSize(jPanel5.getWidth(), jPanel5.getHeight());

            myChartPanel.setVisible(true);

            jPanel5.removeAll();

            jPanel5.add(myChartPanel);

            jPanel5.revalidate();

            jPanel5.repaint();
    }//GEN-LAST:event_jmiHistogramaActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Mediaana(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        FrmSomarImagens ObjFrmSomarImagens = new FrmSomarImagens();
        ObjFrmSomarImagens.setVisible(true);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
         int a = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor de 'a':"));
         int b = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor de 'b':"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Expansao(ImagemAtual, a, b);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        int a = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor de 'a':"));
         int b = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor de 'b':"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Compressao(ImagemAtual, a, b);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Moda(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Min(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem10ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Max(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed

        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Prewit(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem11ActionPerformed

    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Sobel(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem12ActionPerformed

    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem13ActionPerformed
        int Mascara = Integer.parseInt(JOptionPane.showInputDialog(this, "Entre com o valor da mascara(ímpar):"));
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.DesfoqueGaussiano(ImagemAtual, Mascara);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem13ActionPerformed

    private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem14ActionPerformed
        BufferedImage ImagemProcessada = ProcessamentoFotoXop.Scale2x(ImagemAtual);
        ImagemAtual = ImagemProcessada;
        ImagemEmEdicao.setIcon(new ImageIcon(ImagemAtual));
    }//GEN-LAST:event_jMenuItem14ActionPerformed

    private void jMenuItem15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem15ActionPerformed
       double vetorvermelho[] = ProcessamentoFotoXop.HistogramaEqualizado(ImagemAtual,"R");
       double vetorverde[] = ProcessamentoFotoXop.HistogramaEqualizado(ImagemAtual,"G");
       double vetorazul[] = ProcessamentoFotoXop.HistogramaEqualizado(ImagemAtual,"B");
            
       
       
       int quantidade = 256;
            
       HistogramDataset dataset = new HistogramDataset();
       dataset.setType(HistogramType.FREQUENCY);
       dataset.addSeries("Vermelho", vetorvermelho, quantidade);
       dataset.addSeries("Verde", vetorverde, quantidade);
       dataset.addSeries("Azul", vetorazul, quantidade);
       String plotTitle = "Histograma Equalizado";
       String xaxis = "Nivel de Cinza";
       String yaxis = "Frequencia";
       PlotOrientation orientation = PlotOrientation.VERTICAL;
       boolean show = false;
       boolean toolTips = false;
       boolean urls = false;

            // cria o gráfico
            JFreeChart grafico = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls);
             
            ChartPanel myChartPanel = new ChartPanel(grafico, true);

            myChartPanel.setSize(jPanel5.getWidth(), jPanel5.getHeight());

            myChartPanel.setVisible(true);

            jPanel5.removeAll();

            jPanel5.add(myChartPanel);

            jPanel5.revalidate();

            jPanel5.repaint();
    }//GEN-LAST:event_jMenuItem15ActionPerformed

    /**
         * @param args the command line arguments
         */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField EdtCaminhoImagem;
    private javax.swing.JLabel ImagemEmEdicao;
    private javax.swing.JLabel LbPontodeProva;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem15;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JButton jbtnAbrirImagem;
    private javax.swing.JMenu jmenuAjuda;
    private javax.swing.JMenu jmenuEfeitos;
    private javax.swing.JMenuBar jmenuPrincipal;
    private javax.swing.JMenu jmenuSobre;
    private javax.swing.JMenuItem jmiAntiLogaritmo;
    private javax.swing.JMenuItem jmiHistograma;
    private javax.swing.JMenuItem jmiLogaritmo;
    private javax.swing.JMenuItem jmiMedia;
    private javax.swing.JMenuItem jmiNegativo;
    private javax.swing.JMenuItem jmiPotencia;
    private javax.swing.JMenuItem jmiQuantizacao;
    private javax.swing.JMenuItem jmiRaiz;
    private javax.swing.JMenuItem jmiRotacao90AntiHorario;
    private javax.swing.JMenuItem jmiRotacao90Horario;
    private javax.swing.JMenuItem jmirotacao180;
    // End of variables declaration//GEN-END:variables
}
